package com.kfm.jdbc.day02;

import java.sql.SQLException;

public class Test {

    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/company_info";
        String user = "root";
        String pass = "root";

        DBHelper dbHelper = new DBHelper(url, user, pass);

        try {
            // 开启事务
            dbHelper.startTransaction();

            String sql = "update customer set balance = balance - ? where customerName = ?";

            dbHelper.update(sql, 100, "老兵");

            dbHelper.update(sql, -100, "新兵");

            // 回滚事务
            dbHelper.rollback();

            dbHelper.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
